﻿using System;
using System.Globalization;
using System.Management.Automation;
using System.Management.Automation.Host;
using BGShell.PowerShell.Runspaces;

namespace BGShell.PowerShell.Host
{
    internal sealed class RunspacePSHost : PSHost
    {
        private readonly RunspacePSHostUI _ui;
        private readonly PSObject _private;
        
        private readonly RunspaceHostInfo _info;
        private readonly RunspaceProxyService _owner;

        public RunspacePSHost(RunspaceProxyService owner, RunspaceHostInfo hostInfo, IRunspaceHostUI hostUi, Object privateObject)
        {
            _owner = owner;
            _info = hostInfo;
            _ui = new RunspacePSHostUI(hostUi);
            _private = PSObject.AsPSObject(privateObject);
        }

        public override CultureInfo CurrentCulture
        {
            get { return _info.CurrentCulture; }
        }

        public override CultureInfo CurrentUICulture
        {
            get { return _info.CurrentUICulture; }
        }

        public override void EnterNestedPrompt()
        {
            _owner.EnterNestedPrompt();
        }

        public override void ExitNestedPrompt()
        {
            _owner.ExitNestedPrompt();
        }

        public override Guid InstanceId
        {
            get { return _info.InstanceID; }
        }

        public override string Name
        {
            get { return _info.Name; }
        }

        public override void NotifyBeginApplication()
        {
            //_owner.NotifyBeginApplication();
        }

        public override void NotifyEndApplication()
        {
            //_owner.NotifyEndApplication();
        }

        public override void SetShouldExit(int exitCode)
        {
            _owner.SetShouldExit(exitCode);
        }

        public override PSHostUserInterface UI
        {
            get { return _ui; }
        }

        public override Version Version
        {
            get { return _info.Version; }
        }

        public override PSObject PrivateData
        {
            get { return _private; }
        }
    }
}
